package com.atguigu.lease.web.admin.controller.apartment;


import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.model.entity.LabelInfo;
import com.atguigu.lease.model.enums.ItemType;
import com.atguigu.lease.web.admin.service.LabelInfoService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "标签管理")
@RestController
@RequestMapping("/admin/label")
public class LabelController {

    @Autowired
    private LabelInfoService labelInfoService;

   @Operation(summary = "根据类型查询标签列表")
   @GetMapping("list")
   public Result<List<LabelInfo>> list(@RequestParam("type") ItemType type){
       LambdaQueryWrapper<LabelInfo> wrapper = new LambdaQueryWrapper<>();
       wrapper.eq(LabelInfo::getType,type);
       List<LabelInfo> list = labelInfoService.list(wrapper);
       return Result.ok(list);
   }
   @Operation(summary = "保存或者更新标签")
   @PostMapping("saveOrUpdate")
   public Result<String> saveOrUpdate(@RequestBody LabelInfo labelInfo){
       labelInfoService.saveOrUpdate(labelInfo);
       return Result.ok("保存成功");
   }
   @Operation(summary = "根据id删除标签")
   @PostMapping("deleteById")
   public Result<String> deleteById(@RequestParam("id") Long id){
       labelInfoService.removeById(id);
       return Result.ok("删除成功");
   }
   }